//
//  NewsChildFromViewController.m
//  Gxj
//
//  Created by 刘伟 on 2017/9/13.
//  Copyright © 2017年 wkq. All rights reserved.
//

#import "NewsChildFromViewController.h"
#import "NewsFromTableViewCell.h"

@interface NewsChildFromViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic,strong) UITableView *tableView;

@property (nonatomic,assign) BOOL isClickCell;
@property (nonatomic,assign) NSInteger inter;

@end

@implementation NewsChildFromViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.view addSubview:self.tableView];
}

#pragma mark - tableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 81;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    self.isClickCell = YES;
    self.inter = indexPath.row;
    [self.tableView reloadData];
    NSLog(@"第%ld消息已读",(long)indexPath.row);
}

#pragma mrak - tableViewDataSource
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NewsFromTableViewCell *cell;
    
    if (!cell)
    {
        cell = [[NewsFromTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
    if (indexPath.row == 0) {
        [cell.userHead setImage:[UIImage imageNamed:@"xitong"] forState:0];
        cell.userName.text = @"系统推送";
        cell.userNews.text = @"情人节马上就要来到了，亲爱的宝宝们福利马上就要发放了！请准备";
        cell.timeLab.text = @"1小时前";
    }
    
    if (self.isClickCell)
    {
        if (self.inter == indexPath.row)
        {
            cell.isRead.image = [UIImage imageNamed:@"yidu"];
        }
    }

    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (UITableView *)tableView
{
    if (!_tableView)
    {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, UIScreenHeight - 108) style:UITableViewStylePlain];
        
        _tableView.delegate = self;
        
        _tableView.dataSource = self;
    }
    return _tableView;
}

@end
